<template>
    <div class="wrapper">
        <el-form :model="formInline">
            <el-form-item label="设备编号">
                <el-input v-model="formInline.devicecode" placeholder="设备编号"></el-input>
            </el-form-item>
            <el-form-item label="唯一辨识码">
                <el-input v-model="formInline.uniquecode" placeholder="唯一辨识码"></el-input>
            </el-form-item>
            <el-form-item label="类型">
                <el-select v-model="formInline.type" placeholder="类型">
                    <el-option v-for="item in typelist" :key="item.id" :label="item.name" :value="item.id"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="设备状态">
                <el-select v-model="formInline.status" placeholder="设备状态">
                    <el-option label="已绑定" :value="true"></el-option>
                    <el-option label="未绑定" :value="false"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitadd">提交</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import request from '../untils/request'
export default {
    data(){
        return {
            formInline: {
                devicecode: '',
                uniquecode: '',
                type: '',
                status: '',
                page: 1,
                size: 3,
            },
            id: this.$route.query.id,
            typelist: []
        }
    },
    created(){
        this.gettype()
        this.getInfo()
    },
     methods: {
        getInfo(){
            // 初始化数据
            request.get(`/device/list/${this.id}`).then(res => {
                this.formInline = res
            })
        },
        gettype(){
            request.get('/goods/type').then(res => {
                this.typelist = res.results
            })
        },
        submitadd(){
            let data = this.formInline
             request.put(`/device/list/${this.id}/`, data).then(res => {
                this.$message.success('编辑成功')
                window.setTimeout(() => {
                    this.$router.push({
                        name: "Home"
                    })
                }, 500)
            })
        }
     }
}
</script>
<style>

</style>